package com.lan3g.Test.view;

import com.lan3g.Test.util.VerifyCode;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

@WebServlet(name = "VerifyServlet",urlPatterns = "/verify")
public class VerifyServlet extends HttpServlet {

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            VerifyCode verifyCode = new VerifyCode();
            BufferedImage image = verifyCode.getImage();
            ServletOutputStream os = response.getOutputStream();
            verifyCode.out(image,os);// 把图片输出到页面中

            //把验证码的值 放到session域当中
            String text = verifyCode.getText();
            request.getSession().setAttribute("verify",text);
        }


        protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request,response);

    }
}
